package cn.tedu.service;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.tedu.dao.UserDao;
import cn.tedu.entity.User;
import cn.tedu.util.EmpUtil;
import cn.tedu.util.JsonResult;

@Service("userService")
public class UserServiceImpl implements UserService{

	@Resource
	private UserDao userDao;
	
	public JsonResult<User> checkLogin(String username, String password) {
		//鎺ユ敹缁撴灉鏁版嵁
		JsonResult<User> result = new JsonResult<User>();
		//鏍规嵁鐢ㄦ埛鍙傛暟鏌ヨ鐢ㄦ埛淇℃伅
		User user = userDao.findByName(username);
		
		if (user == null) {
			result.setStatus(1);
			result.setMsg("璐﹀彿涓嶅瓨鍦�");
			return result;
		}
		String md5password = EmpUtil.md5(password); 
		System.out.println(md5password);
		if (!user.getPassword().equals(md5password)) {
			result.setStatus(2);
			result.setMsg("瀵嗙爜閿欒");
			return result;
		}
		
		result.setStatus(0);
		result.setData(user);
		return result;
	}

}
